/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.futuremind.recyclerviewfastscroll.viewprovider;

import com.futuremind.recyclerviewfastscroll.FastScroller;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Text;
import ohos.app.Context;

/**
 * ScrollerViewProvider
 *
 * @since 2021-03-26
 */
public abstract class ScrollerViewProvider {
    private FastScroller scroller;
    private ViewBehavior handleBehavior;
    private ViewBehavior bubbleBehavior;

    /**
     * setFastScroller233
     *
     * @param scroer 去
     */
    public void setFastScroller(FastScroller scroer) {
        this.scroller = scroer;
    }

    /**
     * Context实列
     *
     * @return 1
     */
    protected Context getContext() {
        return scroller.getContext();
    }

    protected FastScroller getScroller() {
        return scroller;
    }

    /**
     * Component
     *
     * @param container q
     * @return Component
     */
    public abstract Component provideHandleView(ComponentContainer container);

    /**
     * provideBubbleView
     *
     * @param container q
     * @return Component
     */
    public abstract Component provideBubbleView(ComponentContainer container);

    /**
     * provideBubbleTextView
     *
     * @return A {@link Text} that will hold the index title.
     */
    public abstract Text provideBubbleTextView();

    /**
     * getBubbleOffset
     *
     * @return the position of the bubble in relation to the handle (according to the orientation).
     */
    public abstract int getBubbleOffset();

    /**
     * ViewBehavior
     *
     * @return ViewBehavior
     */
    protected abstract ViewBehavior provideHandleBehavior();

    /**
     * ViewBehavior
     *
     * @return ViewBehavior
     */
    protected abstract ViewBehavior provideBubbleBehavior();

    /**
     * getHandleBehavior
     *
     * @return ViewBehavior
     */
    protected ViewBehavior getHandleBehavior() {
        if (handleBehavior == null) {
            handleBehavior = provideHandleBehavior();
        }
        return handleBehavior;
    }

    /**
     * ViewBehavior
     *
     * @return ViewBehavior
     */
    protected ViewBehavior getBubbleBehavior() {
        if (bubbleBehavior == null) {
            bubbleBehavior = provideBubbleBehavior();
        }
        return bubbleBehavior;
    }

    /**
     * onHandleGrabbed
     */
    public void onHandleGrabbed() {
        if (getHandleBehavior() != null) {
            getHandleBehavior().onHandleGrabbed();
        }
        if (getBubbleBehavior() != null) {
            getBubbleBehavior().onHandleGrabbed();
        }
    }

    /**
     * onHandleReleased
     */
    public void onHandleReleased() {
        if (getHandleBehavior() != null) {
            getHandleBehavior().onHandleReleased();
        }
        if (getBubbleBehavior() != null) {
            getBubbleBehavior().onHandleReleased();
        }
    }

    /**
     * onScrollStarted
     */
    public void onScrollStarted() {
        if (getHandleBehavior() != null) {
            getHandleBehavior().onScrollStarted();
        }
        if (getBubbleBehavior() != null) {
            getBubbleBehavior().onScrollStarted();
        }
    }

    /**
     * onScrollFinished
     */
    public void onScrollFinished() {
        if (getHandleBehavior() != null) {
            getHandleBehavior().onScrollFinished();
        }
        if (getBubbleBehavior() != null) {
            getBubbleBehavior().onScrollFinished();
        }
    }
}
